﻿/*
 * 创建人:lf
 * 创建时间:2021/5/20 16:42:20
 * 描述:
 * */

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using Furion.DatabaseAccessor;
using Furion.DependencyInjection;

 

using Purchasing.Core;
using Furion.JsonSerialization;
using MapsterMapper;
using Microsoft.Extensions.Logging;
using Microsoft.EntityFrameworkCore;

namespace Purchasing.Web.Core
{
    public interface IToubiao
    {
        public Task<string> GetAll(string keyword);
    }
    public class ToubiaoService:IToubiao, ITransient
    {

        private readonly ILogger<ToubiaoService> _logger;
        private readonly IRepository<UfToubiaoinfo> _repository;
        private readonly IMapper _mapper;
        private readonly IJsonSerializerProvider _jsonSerializer;

        public ToubiaoService(ILogger<ToubiaoService> logger, IRepository<UfToubiaoinfo> repository, IMapper mapper, IJsonSerializerProvider jsonSerializer)
        {
            this._logger = logger;
            this._repository = repository;
            this._mapper = mapper;
            this._jsonSerializer = jsonSerializer;
        }

        public async Task<string> GetAll(string keyword)
        {
            //动态修改仓储模式(只读)
            var readRepository = _repository.Constraint<IReadableRepository<UfToubiaoinfo>>();
            //查询所有数据
            var list = await readRepository.AsQueryable().ToListAsync();
            /*            var list = await readRepository.Where(!string.IsNullOrWhiteSpace(keyword), o => o.zbn.Contains(keyword)).ToListAsync();*/
            _logger.LogInformation("获得了HrmSubCompany表的所有数据");

       /*     var dtos = _mapper.Map<List<CompanyDto>>(list);
            _logger.LogInformation("数据已经格式化");*/

            return _jsonSerializer.Serialize(list);
        }
    }
}
